package cn.hh.modules.basic.api;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.hh.modules.shiro.config.ShiroConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;

@RestController
@RequestMapping("/api")
@Api
public class IndexController {

    @Value(value = "${spring.application.name}")
    private String applicationName;

    @Autowired
    private ShiroConfig shiroConfig;

    @GetMapping("/")
    public void index(HttpServletRequest request, HttpServletResponse response) throws IOException {
        shiroConfig.redisManager();
        StringBuilder builder = new StringBuilder();
        builder.append( "<html>" )
                .append( "<body>" )
                .append( "<h2 style=\"margin: 50px 0 0 80px;\">" )
                .append( "您好，欢迎访问【" + applicationName + "】" )
                .append( "</h2>" )
                .append( "</body>" )
                .append( "</html>" );
        response.setHeader( "content-type", "text/html;charset=UTF-8" );
        response.getWriter().write( builder.toString() );
    }

}
